﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Pot4a00DAL : Pot4a00Base
    {
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public SqlApp UpdateModel(Model.Pot4a00 pot4a00)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Pot4a00 set ");
            strSql.Append("startdate=@startdate ,endate=@endate ,nprice=@nprice ");
            strSql.Append("where listid=@listid ");
            SqlParameter[] parameters = {
				new SqlParameter("@startdate", SqlDbType.DateTime),
				new SqlParameter("@endate", SqlDbType.DateTime),
				new SqlParameter("@nprice", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = pot4a00.Startdate;
            parameters[1].Value = pot4a00.Endate;
            parameters[2].Value = pot4a00.Nprice;
            parameters[3].Value = pot4a00.Listid;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "数据保存失败！");
        }

        public SqlApp DeleteByListid(string promocode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM Pot4a01 ");
            strSql.Append(" where plistid=@listid ");
            SqlParameter[] parameters = {
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = promocode;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "更新失败！");
        }

        public SqlApp DeleteForUpdate(string promocode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM Pot4a00 ");
            strSql.Append(" where promocode = @promocode ");
            SqlParameter[] parameters = {
				new SqlParameter("@promocode", SqlDbType.NVarChar)
				};
            parameters[0].Value = promocode;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "更新促销表失败！");
        }

        /// <summary>
        /// 根据促销号更新促销结束时间
        /// </summary>
        /// <param name="promocode"></param>
        /// <returns></returns>
        public SqlApp UpdateEndDate(string promocode, DateTime endate)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE Pot4a00 SET endate=@endate");
            strSql.Append(" where promocode = @promocode AND endate >= GETDATE() ");
            SqlParameter[] parameters = {
				new SqlParameter("@promocode", SqlDbType.NVarChar),
                    new SqlParameter("@endate", SqlDbType.DateTime)
				};
            parameters[0].Value = promocode;
            parameters[1].Value = endate;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "该促销已经结束，不能修改！");
        }

    }
}

